hysop.fields.discrete_field module

Discrete fields (scalars or vectors) descriptions. * DiscreteScalarFieldViewContainerI * DiscreteScalarField * DiscreteTensorField * DiscreteScalarFieldView

hysop.fields.discrete_field.DiscreteField = (<class 'hysop.fields.discrete_field.DiscreteScalarField'>, <class 'hysop.fields.discrete_field.DiscreteTensorField'>)

A DiscreteField is either of DiscreteScalarField or a DiscreteTensorField

class hysop.fields.discrete_field.DiscreteScalarField(field, topology, register_discrete_field=True, name=None, pretty_name=None, var_name=None, latex_name=None, **kwds)[source]

Bases: NamedScalarContainerI, TaggedObject

Discrete representation of scalar or vector fields,

A DiscreteScalarField is distributed set of mesh data (hysop.mesh.mesh.Mesh) wich are a collection of numpy like multidimensional arrays allocated using a specific backend (hysop.core.arrays.array.ArrayBackend).

A DiscreteScalarField is the result of discretizing a continuous Field (hysop.field.continuous_field.Field) defined on a specific domain (hysop.domain.domain.Domain) distributed accross processes through a topology (hysop.topology.topology.Topology).

Ghost exchangers are automatically built for all discrete fields. Ghost exchangers may require additional memory buffers, depending on the discrete field topology backend and the ghost exchange strategy.

Creates a discrete field for a given continuous field and topology.

Parameters:
  • field (Field) – The continuous field that is dicrerized.

  • topology (Topology) – The topology where to allocate the discrete field.

  • register_discrete_field (bool, defaults to True) – If set register input topology to input continuous field.

  • name (string, optional) – A name for the field.

  • pretty_name (str, optional.) – A pretty name used for display whenever possible. Defaults to name.

  • var_name (string, optional.) – A variable name used for code generation. This will be passed to the symbolic representation of this discrete field.

  • latex_name (string, optional.) – A variable name used for latex generation. This will be passed to the symbolic representation of this discrete field.

  • kwds (dict) – Base class arguments.

static __new__(cls, field, topology, register_discrete_field=True, name=None, pretty_name=None, var_name=None, latex_name=None, **kwds)[source]

Creates a discrete field for a given continuous field and topology.

Parameters:
  • field (Field) – The continuous field that is dicrerized.

  • topology (Topology) – The topology where to allocate the discrete field.

  • register_discrete_field (bool, defaults to True) – If set register input topology to input continuous field.

  • name (string, optional) – A name for the field.

  • pretty_name (str, optional.) – A pretty name used for display whenever possible. Defaults to name.

  • var_name (string, optional.) – A variable name used for code generation. This will be passed to the symbolic representation of this discrete field.

  • latex_name (string, optional.) – A variable name used for latex generation. This will be passed to the symbolic representation of this discrete field.

  • kwds (dict) – Base class arguments.

classmethod format_discrete_names(name, pretty_name, var_name, latex_name, topology)[source]
class hysop.fields.discrete_field.DiscreteScalarFieldView(dfield, topology_state, **kwds)[source]

Bases: DiscreteScalarFieldViewContainerI, TaggedObjectView, VariableTag

View over a DiscreteScalarField (taking into account a topology state).

__contains__(obj)[source]

Check if a scalar object is contained in self.

__iter__()[source]

Return an iterator on unique scalar objects.

__tuple__()[source]

Fix hysop.tools/type.to_tuple for FieldContainers, because __iter__ has been redefined.

property backend

Get the array backend used to allocate this discrete field data.

property backend_kind

Get the array backend kind used to allocate this discrete field data.

property dfield

Get the discrete field on which the view is.

discrete_field_views()[source]

Return all unique discrete field views contained in this discrete field view container.

property domain

Return a domain view on which this discrete field is defined.

property dtype

Get the data type of the discrete field.

property field

Get the continuous field on which the view is.

honor_memory_request(*args, **kwds)[source]
property initial_values

Get the default initial values of this field as a tuple (compute, ghosts).

property is_read_only

Return true if this view is a read-only.

property is_tensor
property latex_name

Get the latex name of the discrete field.

match(other, invert=False)[source]

Check if two DiscreteScalarFieldViews are equivalent.

property memory_request

Get memory request that should be allocated for this TmpCartesianDiscreteField.

property memory_request_id

Get memory request id that should be allocated for this TmpCartesianDiscreteField.

property mesh

Return a mesh view on which the current process operate for this discrete field.

property name

Get the name of the discrete field.

nd_iter()[source]

Return an nd-indexed iterator of contained objects.

property ndim

Number of dimensions of this this tensor.

property pretty_name

Get the name of the discrete field.

property s
property symbol
property topology

Return a topology view on which this discrete field is defined.

property topology_state

Get the topology state of this view.

property var_name

Get the latex name of the discrete field.

class hysop.fields.discrete_field.DiscreteScalarFieldViewContainerI(**kwds)[source]

Bases: object

Common abstract interface for scalar and tensor-like container of discrete field views.

abstract accumulate_ghosts(**kwds)[source]

Specialization of ghost exchange for ghost summation.

abstract as_any_dfield(memory_order, **kwds)[source]

Quickly take a view on this DiscreteScalarFieldView using self topology state supplemented by a MemoryOrdering.

as_contiguous_dfield(**kwds)[source]

Quickly take a view on this DiscreteScalarFieldView using self topology state supplemented by a MemoryOrdering.C_CONTIGUOUS.

as_fortran_dfield(**kwds)[source]

Quickly take a view on this DiscreteScalarFieldView using self topology state supplemented by a MemoryOrdering.F_CONTIGUOUS.

property backend

Try to return the unique backend common to all contained discrete fields, else raise an AttributeError.

property backend_kind

Try to return the unique backend kind common to all contained discrete fields, else raise an AttributeError.

abstract build_ghost_exchanger(**kwds)[source]

Build a ghost exchanger, possibly on different data. Usefull for operator apply.

abstract clone(tstate=None)[source]

Create a new temporary DiscreteScalarField container and allocate it like the current object, with possibly a different topology state.

This should only be used for debugging and testing purpose. The generated discrete field is not registered to the continuous field.

continuous_fields()[source]

Return all unique continuous fields contained in this discrete field view container.

abstract copy(from_dfield, **kwds)[source]

Fill this discrete field with values from another one.

property ctype

Get the data type of the discrete field as a C type (may raise AttributeError).

property dfields

Alias for self.discrete_field_views().

property dim

Get dimension of the shared domain (may raise AttributeError).

abstract discrete_field_views()[source]

Return all unique discrete field views contained in this discrete field view container.

discrete_fields()[source]

Return all unique discrete fields contained in this discrete field view container.

property domain

Try to return the unique topology view common to all contained discrete fields, else raise an AttributeError.

property dtype

Try to return the unique data type common to all contained discrete fields, else raise an AttributeError.

abstract exchange_ghosts(build_launcher=False, **kwds)[source]

Exchange ghosts using cached ghost exchangers which are built at first use. ie. Exchange every ghosts components of self.data using current topology state. By default all ghosts are exchanged.

abstract fill(**kwds)[source]

Fill all contained discrete field with an initial value.

get_attributes(*attrs)[source]

Return all matching attributes contained in self.discrete_field_views(), as a tuple.

get_attributes_as_tensor(*attrs)[source]

Return all matching attributes contained in self.discrete_field_views(), as a np.ndarray of objects of the same shape.

get_unique_attribute(*attr)[source]

Try to return the unique attribute common to all contained discrete fields. Raise an AttributeError if a attribute is not unique accross contained discrete field views.

/!Can be slow to evaluate due to uniqueness check /!

abstract has_ghosts()[source]

Return True if any contained discrete field requires ghost exchanges.

has_unique_attribute(*attr)[source]

Return true if all contained discrete fields share the same attribute (as stated by the == comparisson operator).

/!Can be slow to evaluate /!

has_unique_backend()[source]

Return true if all contained discrete fields share the same backend.

has_unique_backend_kind()[source]

Return true if all contained discrete fields share the same backend kind.

has_unique_domain()[source]

Return true if all contained discrete fields share the same domain view.

has_unique_dtype()[source]

Return true if all contained discrete fields share the same data type.

has_unique_mesh()[source]

Return true if all contained discrete fields share the same mesh view.

has_unique_topology()[source]

Return true if all contained discrete fields share the same topology view.

has_unique_topology_state()[source]

Return true if all contained discrete fields share the same topology state.

id_to_component(val)[source]
ids_to_components(ids)[source]

Convert tensor coordinates into 1d offsets.

abstract initialize(**kwds)[source]

Initialize all contained discrete fields.

abstract integrate(**kwds)[source]

Sum all the values in the mesh.

property is_scalar
abstract long_description()[source]

Long description of this field as a string.

abstract match(other, invert=False)[source]

Check if two DiscreteScalarFieldViews are equivalent.

property mesh

Try to return the unique mesh view common to all contained discrete fields, else raise an AttributeError.

property nb_components

Total number of components of this discrete field container, exluding None entries, but including duplicate fields.

abstract randomize(**kwds)[source]

Fill all contained discrete field with random values.

abstract short_description()[source]

Short description of this field as a string.

abstract tmp_dfield_like(name, **kwds)[source]

Create a new Field container and a new temporary CartesianDiscreteField. like the current object, possibly on a different backend. /!The returned discrete field is not allocated.

property topology

Try to return the unique topology view common to all contained discrete fields, else raise an AttributeError.

property topology_state

Try to return the unique topology state common to all contained discrete fields, else raise an AttributeError.

abstract view(topology_state)[source]

Return a view on this DiscreteScalarField using given topology state.

class hysop.fields.discrete_field.DiscreteTensorField(field, dfields, name=None, pretty_name=None, latex_name=None, **kwds)[source]

Bases: NamedTensorContainerI, DiscreteScalarFieldViewContainerI, TaggedObject

A tensor discrete field is a collection of scalar discrete fields views.

This object handles a numpy.ndarray of discrete scalar field views, which may have different attributes (different data types for example) and different topology states.

A tensor field garanties that each different field objects have unique names and pretty names within the tensor field. A given continuous scalar discrete field may appear at multiple indices with different views.

Some components may also be set to None.

Is also garanties that all fields shares the same domain, but contained discrete fields may be defined on different topologies.

Create an abstract named object that contains a symbolic value. name : string

A name for the field.

pretty_name: string, optional.

A pretty name used for display whenever possible. Defaults to name.

kwds: dict

Keywords arguments for base class.

accumulate_ghosts(build_launcher=False, build_exchanger=False, evt=None, **kwds)[source]

Exchange ghosts using cached ghost exchangers which are built at first use. ie. Exchange every ghosts components of self.data using current topology state. Specialization for ghost summation.

as_any_dfield(memory_order, name=None, pretty_name=None, **kwds)[source]

Quickly take a view on this DiscreteScalarFieldView using self topology state supplemented by a MemoryOrdering.

as_contiguous_dfield(**kwds)[source]

Quickly take a view on this DiscreteScalarFieldView using self topology state supplemented by a MemoryOrdering.C_CONTIGUOUS.

as_fortran_dfield(**kwds)[source]

Quickly take a view on this DiscreteScalarFieldView using self topology state supplemented by a MemoryOrdering.F_CONTIGUOUS.

property buffers
build_ghost_exchanger(**kwds)[source]

Build a ghost exchanger, possibly on different data. Usefull for operator apply.

clone(tstate=None, name=None, pretty_name=None, **kwds)[source]

Create a new temporary DiscreteScalarField container and allocate it like the current object, with possibly a different topology state.

This should only be used for debugging and testing purpose. The generated discrete field is not registered to the continuous field.

common_dtype()[source]

Return common data type of contained fields.

copy(from_dfield, **kwds)[source]

Fill this discrete field with values from another one.

property data
classmethod determine_tensor_cls(dfields)[source]

Determine the Tensor container best suited for contained dfields.

discrete_field_views()[source]

Return all unique discrete field views contained in this discrete field view container.

distance(*args, **kwds)[source]
exchange_ghosts(build_exchanger=False, build_launcher=False, evt=None, **kwds)[source]

Exchange ghosts using cached ghost exchangers which are built at first use. ie. Exchange every ghosts components of self.data using current topology state. By default all ghosts are exchanged.

fill(*args, **kwds)[source]

Fill all contained discrete field with an initial value.

classmethod from_dfield_array(name, dfields, pretty_name=None, **kwds)[source]

Create a TensorField and a DiscreteTensorField from np.ndarray of discrete fields.

classmethod from_dfields(name, dfields, shape, pretty_name=None, **kwds)[source]

Create a TensorField and a DiscreteTensorField from a list of discrete fields and a shape.

has_ghosts()[source]

Return True if any contained discrete field requires ghost exchanges.

honor_memory_request(work, op=None)[source]

Honour memory requests for contained temporary discrete fields.

initialize(*args, **kwds)[source]

Initialize all contained discrete fields.

integrate(scale=True, dtype=None, **kwds)[source]

Compute volume integrals by suming values scaled by elementary volume dx.

property is_tensor
long_description()[source]

Long description of this discrete field container.

match(other, invert=False)[source]

Check if two DiscreteScalarFieldViews container are equivalent.

norm(*args, **kwds)[source]
randomize(*args, **kwds)[source]

Fill all contained discrete field with random values.

property sbuffer
property sdata
short_description()[source]

Short description of this discrete field container.

tmp_dfield_like(name, pretty_name=None, **kwds)[source]

Create a new Field container and a new temporary CartesianDiscreteField. like the current object, possibly on a different backend. /!The returned discrete field is not allocated.

view(topology_state, name, pretty_name=None)[source]

Return a view on contained DiscreteFields using given topology state.